<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateWithdrawsTable extends Migration
{
    public function up()
    {
        Schema::create('withdraws', function (Blueprint $table) {
            $table->id();
	        $table->unsignedBigInteger('user_id')->index()->default(0)->comment('user');
	        $table->unsignedBigInteger('batch_withdraw_id')->index()->default(0);
	        $table->string('alipay_user_id')->nullable();
	        $table->string('number')->index()->comment('number of this withdraw');
	        $table->decimal('target_amount', 10, 2)->default(0)->comment('how much withdrawing');
	        $table->string('charge_type')->default('in')->comment('deduct service charge from the amount of withdraw money or of user total money');
	        $table->decimal('charge_amount', 10, 2)->default(0)->comment('pay service charge to platform');
	        $table->decimal('actual_amount', 10, 2)->default(0)->comment('pay service charge to platform');
	        $table->string('method')->default('alipay')->comment('withdraw by one of the payments');
	        $table->string('channel')->default('local')->comment('local, freelance');
	        $table->text('remark')->nullable()->comment('memo of this withdraw, usually happens with offline');
	        $table->text('info')->nullable()->comment('infomation about this withdraw, usually happens with offline');
	        $table->dateTime('paid_at')->nullable()->index();
	        $table->string('paid_no')->nullable()->index();
	        $table->string('status')->default('pending')->index();
            $table->timestamps();
	        $table->index(['created_at']);
        });
    }
    
    public function down()
    {
        Schema::dropIfExists('withdraws');
    }
}
